<?
	function hashPassword ($cClave)
		{
			if ( CLAVE_CASE_SENSITIVE == false ) $cClave = strtolower($cClave);
			if ( CLAVE_SAVE_AS_HASH == true )  $cClave = sha1( $cClave );
			return $cClave;
    }

	function getConfigArray( $cModule, $nAction, $nTipo )
	{
		global $aInstallModules;
		$oModule =& loadModule( "seguridad" );
		$nModule = $aInstallModules[$cModule]['nModule'] ;
		$cSql ="SELECT cNombre, cValor FROM stUsuarioConfiguracion WHERE nAccion = $nAction AND nTipo = $nTipo AND nModulo = $nModule AND (ncUsuario = " . $oModule->oUserSession->getUser(). " OR ncUsuario IS NULL)  ";
		//if ( $oModule->oDatabase )
		return $oModule->oDatabase->getKeyArray( $cSql ) ;
	}
	function getConfig( $cModule, $nAction, $nTipo, $cName )
	{
		global $aInstallModules;
		$oModule =& loadModule( "seguridad" );
		$nModule = $aInstallModules[$cModule]['nModule'] ;
		$cSql ="SELECT cValor FROM stUsuarioConfiguracion WHERE nAccion = $nAction AND nTipo = $nTipo AND nModulo = $nModule AND cNombre = '$cName' AND (ncUsuario = " . $oModule->oUserSession->getUser(). " OR ncUsuario IS NULL) ";
		if ( $oModule->oDatabase )
			return $oModule->oDatabase->getData( $cSql ) ;
	}

	function setConfig( $cModule, $nAction, $nTipo, $cName, $cValue, $ncUsuario ='')
	{
		global $aInstallModules;
		$oModule =& loadModule( "seguridad" );
		$nModule = $aInstallModules[$cModule]['nModule'] ;
		if ( $ncUsuario =='' ) $ncUsuario = $oModule->oUserSession->getUser();
		$cSql ="SELECT ncConfiguracion FROM stUsuarioConfiguracion WHERE nAccion = $nAction AND nTipo = $nTipo AND nModulo = $nModule AND cNombre = '$cName' AND (ncUsuario = " . $oModule->oUserSession->getUser(). " OR ncUsuario IS NULL) ";
		$ncConfiguracion = $oModule->oDatabase->getData( $cSql ) ;
		if ( $ncConfiguracion )
		{
			$oModule->oDatabase->update( "stUsuarioConfiguracion",
						"cValor", $cValue,
						"WHERE",
						"ncConfiguracion", $ncConfiguracion) ;
		} else
		{
			$ncConfiguracion = $oModule->oDatabase->nextKey("stUsuarioConfiguracion", "ncConfiguracion" );
			$oModule->oDatabase->insert( "stUsuarioConfiguracion",
						"ncUsuario", $ncUsuario,
						"nModulo", $nModule,
						"nAccion", $nAction,
						"nTipo", $nTipo,
						"cNombre", $cName,
						"cValor", $cValue,
						"ncConfiguracion", $ncConfiguracion) ;
		}
		//echo $oModule->oDatabase->cSql;
	}
	function initializeActores( &$oInput, $cUsuario = "")
	{
		global $aInstallModules;
		$aKeys = explode(";", $oInput->getValue() );
		foreach( $aKeys  as $cKeyValue )
		{
			list ( $cKey, $cValue ) = explode(":", $cKeyValue );
			$aValueActores[strtolower($cKey)] = explode(",", $cValue  );
		}
		foreach ( $aInstallModules as $cKey => $aInstallModule )
		{
			$oModule =& loadModule($cKey);
			$aActores = $oModule->getRoles();
			foreach( $aActores  as $ncActor => $cdActor )
			{
				$oInput->addOption( $cKey . "|" . $ncActor, $cdActor, in_array( $ncActor, $aValueActores[$cKey]) ? 1: 0 , $cKey   );
			}
		}
	}
	function initializeUsuario( &$oInput, $cUsuario = "")
	{
		$oModule =& loadModule( "seguridad" );
		//$oInput->setForm( $this );
		$oInput->addActionArray( 2, $oModule->getActionArray( AGREGAR_UN_USUARIO ), "cUsuario=$cUsuario"  );
		$oInput->addActionArray( 3, $oModule->getActionArray( MODIFICAR_UN_USUARIO ), ""  );
		$cSql = "SELECT ncUsuario, cUsuario FROM stUsuario WHERE bBaja = 0 ORDER BY cUsuario";
		$oInput->setMatrix ( $oModule->oDatabase->getMatrix( $cSql ) );
		$oInput->setLabel('Usuario', 'r');
	}
?>